package com.easy.query.ksp;

import com.easy.query.processor.generate.ClassProxyGenerator;

/**
 * create time 2023/11/8 17:08
 * 文件说明
 * {@link com.easy.query.processor.helper.AptConstant}
 *
 * @author xuejiaming
 */
public class KspConstant {

    public static final String PROXY_TEMPLATE = "package @{package}\n" +
            "\n" +
            "import com.easy.query.core.expression.parser.core.available.TableAvailable\n" +
            "import com.easy.query.core.proxy.AbstractProxyEntity\n" +
            "import com.easy.query.core.proxy.SQLColumn\n" +
            "@{imports}" +
            "\n" +
            "/**\n" +
            " * this file automatically generated by easy-query, don't modify it\n" +
            " * 当前文件是easy-query自动生成的请不要随意修改\n" +
            " * 如果出现属性冲突请使用@ProxyProperty进行重命名\n" +
            " *\n" +
            " * @author easy-query\n" +
            " */\n" +
            "class @{entityClassProxy} : AbstractProxyEntity<@{entityClassProxy}, @{entityClass}>() {\n" +
            "\n" +
            "    companion object {\n\n" +
            "        @JvmStatic\n" +
            "        private val entityClass = @{entityClass}::class.java\n\n" +
            "        @JvmStatic\n" +
            "        val TABLE: @{entityClassProxy} = createTable().createEmpty()\n\n" +
            "        @JvmStatic\n" +
            "        fun createTable() = @{entityClassProxy}()\n\n" +
            "    }" +
            "\n" +
            "\n" +
            "    @{fieldContent}" +
            "\n" +
            "    @Override\n" +
            "    override fun getEntityClass() = Companion.entityClass\n" +
            "\n" +
            "    @{valueObjectContext}\n" +
            "\n" +
            "    @{selectorContext}\n" +
            "\n" +
            "\n" +
            "\n" +
            "    object Fields {\n" +
            "@{fieldStaticContext}" +
            "    }" +
            "\n" +
            "}";



    public static final String FIELD_TEMPLATE = "\n" +
            "    @{comment}\n" +
            "    fun @{proxyProperty}(): @{SQLColumn}<@{entityClassProxy}>{\n" +
            "        return @{sqlColumnMethod}(\"@{property}\")\n" +
            "    }";
    public static final String ANY_FIELD_TEMPLATE = "\n" +
            "    @{comment}\n" +
            "    fun @{proxyProperty}(): @{SQLColumn}<@{entityClassProxy},@{propertyType}>{\n" +
            "        return @{sqlColumnMethod}(\"@{property}\",@{propertyTypeClass})\n" +
            "    }";

    public static final String FIELD_NAVIGATE_TEMPLATE = "\n" +
            "    @{comment}\n" +
            "    fun @{proxyProperty}(): @{propertyProxy}{\n" +
            "        return getNavigate(\"@{property}\", @{propertyProxy}())\n" +
            "    }";
    /**
     * SQLQueryable<MySchoolStudentProxy, MySchoolStudent>
     */
    public static final String FIELD_NAVIGATES_TEMPLATE = "\n" +
            "    @{comment}\n" +
            "    fun @{proxyProperty}(): SQLManyQueryable<@{entityClassProxy},@{propertyProxy},@{propertyType}>{\n" +
            "        return getNavigateMany(\"@{property}\", @{propertyProxy}())\n" +
            "    }";
    public static final String FIELD_VALUE_OBJECT_TEMPLATE = "\n" +
            "    @{comment}\n" +
            "    fun @{proxyProperty}(): @{entityClass}Proxy {\n" +
            "        return getValueObject(@{entityClass}Proxy(getEntitySQLContext(),getTable(), getValueProperty(\"@{property}\")))\n" +
            "    }";


    public static final String FIELD_VALUE_OBJECT_CLASS_TEMPLATE = "\n" +
            "    class @{entityClass}Proxy(entitySQLContext: EntitySQLContext, table: TableAvailable, propertyName: String) : AbstractValueObjectProxyEntity<@{mainEntityClassProxy}, @{entityClass}>(entitySQLContext,table, propertyName) {\n" +
            "\n" +
            "        @{fieldContent}" +
            "\n" +
            "        @{valueObjectContext}" +
            "    }";

    public static final String PROXY_SELECTOR_TEMPLATE =
            "\n" +
            "    /**\n" +
            "    * 数据库列的简单获取\n" +
            "    * @return\n" +
            "    */\n"+
            "    val FETCHER = @{selectorName}(this,null,SQLSelectAsExpression.empty)\n"+
            "\n" +
            "    class @{selectorName}(proxy: @{entityClassProxy}, prev: @{selectorName}?, sqlSelectAsExpression: SQLSelectAsExpression) : AbstractFetcher<@{entityClassProxy},@{entityClass}, @{selectorName}>(proxy, prev, sqlSelectAsExpression) {\n" +
            "\n" +
            "        @{fieldSelectorContent}" +
            "\n" +
            "        override fun createFetcher(cp: @{entityClassProxy}, prev: AbstractFetcher<@{entityClassProxy}, @{entityClass}, @{selectorName}>, sqlSelectExpression: SQLSelectAsExpression): @{selectorName} {\n" +
            "            return @{selectorName}(cp, this, sqlSelectExpression)\n" +
            "        }"+
            "\n" +
            "    }";
    public static final String FIELD_SELECTOR_PROPERTY_TEMPLATE = "\n" +
            "        @{comment}\n" +
            "        fun @{proxyProperty}(): @{selectorName} {\n" +
            "            return add(proxy.@{proxyProperty}())\n" +
            "        }";

    public static final String FIELD_STATIC_TEMPLATE =
            "        const val @{property} = \"@{property}\"\n";






    public static final ClassProxyGenerator PROXY_TEMPLATE_GENERATOR =new ClassProxyGenerator(PROXY_TEMPLATE);
    public static final ClassProxyGenerator FIELD_VALUE_OBJECT_TEMPLATE_GENERATOR=new ClassProxyGenerator(FIELD_VALUE_OBJECT_TEMPLATE);
    public static final ClassProxyGenerator FIELD_NAVIGATES_TEMPLATE_GENERATOR=new ClassProxyGenerator(FIELD_NAVIGATES_TEMPLATE);
    public static final ClassProxyGenerator FIELD_NAVIGATE_TEMPLATE_GENERATOR=new ClassProxyGenerator(FIELD_NAVIGATE_TEMPLATE);
    public static final ClassProxyGenerator ANY_FIELD_TEMPLATE_GENERATOR=new ClassProxyGenerator(ANY_FIELD_TEMPLATE);
    public static final ClassProxyGenerator FIELD_TEMPLATE_GENERATOR=new ClassProxyGenerator(FIELD_TEMPLATE);
    public static final ClassProxyGenerator PROXY_SELECTOR_TEMPLATE_GENERATOR=new ClassProxyGenerator(PROXY_SELECTOR_TEMPLATE);
    public static final ClassProxyGenerator FIELD_SELECTOR_PROPERTY_TEMPLATE_GENERATOR=new ClassProxyGenerator(FIELD_SELECTOR_PROPERTY_TEMPLATE);
    public static final ClassProxyGenerator FIELD_VALUE_OBJECT_CLASS_TEMPLATE_GENERATOR=new ClassProxyGenerator(FIELD_VALUE_OBJECT_CLASS_TEMPLATE);
    public static final ClassProxyGenerator FIELD_STATIC_TEMPLATE_GENERATOR=new ClassProxyGenerator(FIELD_STATIC_TEMPLATE);
}
